var CHECKALLFIELD = false;
function checkfield(identifier, required, checktype, checkmaxnum, checkminnum, checkmaxlength) {
	if(checktype != 'image' && !$('fieldvalue_' + identifier) || !$('checkresult_' + identifier)) {
		return true;
	}
	var ce = $('checkresult_' + identifier);
	var tobj = $('fieldtitle_' + identifier);
	ce.innerHTML = '';
	if(checktype == 'image') {

	} else {
		var checkvalue = $('fieldvalue_' + identifier).value;
	}
	if(required != '0') {
		if(checktype == 'radio' || checktype == 'checkbox') {
			if(checktype == 'radio') {
				var ces = document.getElementsByName("fieldvalue["+identifier+"]");
			} else if(checktype == 'checkbox') {
				var ces = document.getElementsByName("fieldvalue["+identifier+"][]");
			}
			for(var i=0; i<ces.length; i++) {
				if(ces[i].checked) {
					checkdone(ce);
					return true;
				}
			}
			warning(ce, '必填项', tobj);
			return false;
		} else if(checkvalue == '') {
			warning(ce, '必填项', tobj);
			return false;
		} else {
			checkdone(ce);
		}
	}

	if(checktype == 'radio' || checktype == 'checkbox') {
		return true;
	}

	if(checkvalue) {
		if((checktype == 'number' || checktype == 'range' || checktype == 'mobile') && isNaN(checkvalue)) {
			warning(ce, '必须为数字', tobj);
			return false;
		} else if(checktype == 'qq' && !(/^\d{5,12}$/.test(checkvalue))) {
			warning(ce, '必须为QQ数字帐号', tobj);
			return false;
		} else if(checktype == 'mobile' && !(/^((13|15|18)\d{9})$/.test(checkvalue))) {
			warning(ce, '必须为手机号码', tobj);
			return false;
		} else if(checktype == 'telephone' && !(/^(((0\d{2,3}-)?\d{7,8}(-\d{1,4})?))$/.test(checkvalue))) {
			warning(ce, '必须为固定电话格式', tobj);
			return false;
		} else if(checktype == 'email' && !(/^[\-\.\w]+@[\.\-\w]+(\.\w+)+$/.test(checkvalue))) {
			warning(ce, '必须为E-mail格式', tobj);
			return false;
		} else if((checktype == 'text' || checktype == 'textarea') && checkmaxlength != '0' && mb_strlen(checkvalue) > checkmaxlength) {
			warning(ce, '文字过长', tobj);
			return false;
		} else if((checktype == 'number' || checktype == 'range')) {
			if(checkmaxnum != '0' && parseInt(checkvalue) > parseInt(checkmaxnum)) {
				warning(ce, '数值超过允许的最大值', tobj);
				return false;
			} else if(checkminnum != '0' && parseInt(checkvalue) < parseInt(checkminnum)) {
				warning(ce, '数值小于允许的最小值', tobj);
				return false;
			} else {
				checkdone(ce);
			}
		} else {
			checkdone(ce);
		}
	}
	return true;
}

function checkdone(obj) {
	obj.style.display = '';
	obj.innerHTML = '<img src="' + IMGDIR + '/check_right.gif" width="16" height="16" class="vm" />';
}

function warning(obj, msg, titleobj) {
	obj.style.display = '';
	obj.innerHTML = '<img src="' + IMGDIR + '/check_error.gif" width="16" height="16" class="vm" /> ' + msg;
	obj.className = "warning";
	if(CHECKALLFIELD) {
		msg = titleobj.innerHTML + ' ' + msg;
		if(iniframe) {
			alert(msg);
		} else {
			showPrompt(null, null, msg, 1500);
		}
		return false;
	}
}

function valida_ajaxpost(obj) {
	var validate = validateextra(obj)
	if(validate) {
		ajaxpost('form', 'return_formresult');
	} else {
		return validate;
	}
}

function succeedhandle_formresult(url_forward, show_jsmessage, valuesjs) {
	var jumptime = 0;
	$('return_formresult').innerHTML = '';
	$('return_formresult').style.display = 'none';
	if(iniframe) {
		jumptime = 100;
		alert(show_jsmessage);
	} else {
		jumptime = 3500;
		showPrompt(null, null, show_jsmessage, 3000);
	}
	setTimeout(function() {
		url_forward = encodeURI(url_forward);
		location.href=url_forward;
	}, jumptime);
}

function errorhandle_formresult(show_jsmessage, valuesjs) {
	$('return_formresult').innerHTML = '';
	$('return_formresult').style.display = 'none';
	if(iniframe) {
		alert(show_jsmessage);
	} else {
		showPrompt(null, null, show_jsmessage, 1500);
	}
}
